<?php


namespace App\Http\Controllers\Supplier;


use App\Models\NewAdmin;
use App\Services\CommonService;
use App\Services\SmsService;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class VerificationController extends BaseVerifyController
{
    /**
     * 发送短信验证码
     * @param Request $request
     * @return false|string
     */
    public function sendCode(Request $request){
        $mobile = $request->input('mobile');
        if(!$mobile){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL,'参数错误');
        }
        $checkUser  = NewAdmin::where(['mobile'=>$mobile,'is_delete'=>CommonService::IS_DELETE_NOT])->select('status')->first();
        $checkUser = $checkUser?$checkUser->toArray():[];
        if(!$checkUser){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL,'用户不存在');
        }
        if(CommonService::USER_STATUS_NOT == $checkUser['status']){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL,'账号已冻结');
        }
        $res = SmsService::sendCode($mobile);
        if($res['status']){
            return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,$res['msg']);
        }else{
            return ReturnMsg(CommonService::HTTP_CODE_FAIL,$res['msg']);
        }
    }
}
